import request from "../../utils/request"
Page({

    /**
     * 页面的初始数据
     */
    data: {
        userId: 0,
        proList :[],
        orderList: [],
        status: 0
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        // 获取订单
        let userData = wx.getStorageSync('userInfo')
        if(!userData){
            wx.reLaunch({
              url: '/pages/login/login',
            })
        }else{
            let userInfo = JSON.parse(userData)
            this.setData({
                userId: userInfo.userId
            })
            this.getOrderList();
        }
    },
    /*
    修改订单
    */
   toPay(){
        wx.navigateTo({
          url: '/pages/settlement/settlement',
        })
   },
   toProInfo(e){
        let proId = e.currentTarget.dataset.proid
        wx.navigateTo({
          url: '/pages/pro/pro?id='+proId,
        })
   },
   toCancel(){
    
   },
    /*
    获取订单
    */
    async getOrderList(){
        let proData = await request("/order/getByUserId",{userId:this.data.userId,status:this.data.status})
        console.log(this.data.status)
        console.log(proData)
        this.setData({
            orderList: proData.data
        })
        let proList = []
        proData.data.forEach(item => {
            proList.push(item.proInfoVoList[0])          
        });
        this.setData({
            proList
        })
    },
    toall(){
        this.setData({
            status: 0
        })
        this.onLoad()
    },
    toconfirm(){
        this.setData({
            status: 1
        })
        this.onLoad()
    },
    topick(){
        this.setData({
            status: 2
        })
        this.onLoad()
    },
    tofin(){
        this.setData({
            status: 3
        })
        this.onLoad()
    },
    tocancel(){
        this.setData({
            status: 4
        })
        this.onLoad()
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})